package com.xzz.dp;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: hhz
 * @create: 2022-02-17 13:28
 * 119. 杨辉三角 II
 **/
public class GetRow {
    public static void main(String[] args) {
        System.out.println(getRow(5));
    }
    public static List<Integer> getRow(int rowIndex) {
        int[][] dp = new int[rowIndex+1][rowIndex+1];
        dp[0][0]=1;
        for (int i = 1; i < rowIndex + 1; i++) {
            for (int j = 0; j < i + 1; j++) {
                dp[i][j] = dp[i-1][j];
                if(j-1>=0){
                    dp[i][j] += dp[i-1][j-1];
                }
                if(dp[i][j]==0){
                    dp[i][j]=1;
                }
            }
        }
        List<Integer> ans = new ArrayList<>();
        for (int i = 0; i < rowIndex + 1; i++) {
            ans.add(dp[rowIndex][i]);
        }
        return ans;

    }
}
